package com.zhu.shopcenter.zhifubao;


import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import lombok.extern.slf4j.Slf4j;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;



/**
 * 支付宝付款接口
 */
@Configuration
@Slf4j
public class AliPay {
   @Autowired
   private Properties properties;
   public String pay(AlipayBean aliPayBean) throws AlipayApiException {
      AlipayClient client=new DefaultAlipayClient(
              properties.getBaseUrl(),
              properties.getAppId(),
              properties.getSecurityKey(),"JSON","UTF-8",
              properties.getPublicKey(),"RSA2");
      AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
      request.setReturnUrl(properties.getReturnUrl());
      request.setNotifyUrl(properties.getNotifyUrl());
      request.setBizContent(JSON.toJSONString(aliPayBean));
      log.info("封装请求支付宝付款参数为:{}", JSON.toJSONString(request));
      String body = client.pageExecute(request).getBody();
      log.info("请求支付宝付款返回参数为:{}", body);
      return body;
   }
}
